<?php
include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );

include("../../function/function.php");


$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
if (isset($_REQUEST['code'])) {
	$keys = array();
	$keys['code'] = $_REQUEST['code'];
	$keys['redirect_uri'] = WB_CALLBACK_URL;
	try {
		$token = $o->getAccessToken( 'code', $keys ) ;
	} catch (OAuthException $e) {
	}
}

$user_weibo_openid = $token;

$_SESSION['kboy_qq_login'] = "";

if($user_weibo_openid){
	if(getNewsNums("kboy_user","user_weibo_openid='$user_weibo_openid'") >0){
		$_SESSION['kboy_weibo_login'] = "";
		$_SESSION['EmailName'] = "";
		$_SESSION['EmailCode'] = "";
		$_SESSION['kboy_user'] = getClassName("kboy_user","user_email","user_weibo_openid='$user_weibo_openid'");
		$_SESSION['kboy_userid'] = getClassName("kboy_user","uid","user_weibo_openid='$user_weibo_openid'");
		mysql_query("update kboy_user set user_lasttime='$THIS_TODAY_DATETIME',user_lastip='".getip()."' where user_weibo_openid='$user_weibo_openid'");
		echo re("../../../user_index.php");
	}else{
		$_SESSION['kboy_weibo_login'] = $user_weibo_openid;
		echo re("../../../reg.php");
	}
}else{
	echo erro("参数错误");
}
?>